//
// Created by NH55 on 2021/5/30.
//

#ifndef OPENGLC_FILEUTIL_H
#define OPENGLC_FILEUTIL_H

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char* openAndReadFile(char *path) {
    FILE *fp = NULL;
    if ((fp = fopen(path, "rb")) == NULL) {
        return NULL;
    }
    char buffer[512];
    fseek (fp, 0, SEEK_END); // 将文件指针移动到末尾
    char *fragment = (char *) calloc(ftell (fp) , sizeof(char));
    // 重置文件指针
    rewind(fp);
    while (fgets(buffer, 512, (FILE *) fp)){
        strcat(fragment, buffer);
    }
    fclose(fp);
    return fragment ;
}

#endif //OPENGLC_FILEUTIL_H
